Skip to content

Commit 27db432

Browse files
committed
Add classes to support Ada analysis
1 parent 9d06c73 commit 27db432

18 files changed

+1686
-11
lines changed

Diff for: LICENSE-adaic.org.txt

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Ada Reference Manual, ISO/IEC 8652:2007(E) Ed. 3
2+
3+
4+
ISO/IEC 8652:1995(E)
5+
with Technical Corrigendum 1
6+
and Amendment 1
7+
8+
Language and Standard Libraries
9+
10+
11+
Copyright © 1992, 1993, 1994, 1995 Intermetrics, Inc.
12+
Copyright © 2000 The MITRE Corporation, Inc.
13+
Copyright © 2004, 2005, 2006 AXE Consultants
14+
Copyright © 2004, 2005, 2006 Ada-Europe
15+
16+
17+
Ada Reference Manual - Language and Standard Libraries
18+
Copyright © 1992, 1993, 1994, 1995, Intermetrics, Inc.
19+
This copyright is assigned to the U.S. Government. All rights reserved.
20+
This document may be copied, in whole or in part, in any form or by any means,
21+
as is or with alterations, provided that (1) alterations are clearly marked as
22+
alterations and (2) this copyright notice is included unmodified in any copy.
23+
Compiled copies of standard library units and examples need not contain this
24+
copyright notice so long as the notice is included in all copies of source code
25+
and documentation.
26+
27+
28+
Technical Corrigendum 1
29+
Copyright © 2000, The MITRE Corporation. All Rights Reserved.
30+
This document may be copied, in whole or in part, in any form or by any means,
31+
as is, or with alterations, provided that (1) alterations are clearly marked as
32+
alterations and (2) this copyright notice is included unmodified in any copy.
33+
Any other use or distribution of this document is prohibited without the prior
34+
express permission of MITRE.
35+
You use this document on the condition that you indemnify and hold harmless
36+
MITRE, its Board of Trustees, officers, agents, and employees, from any and all
37+
liability or damages to yourself or your hardware or software, or third
38+
parties, including attorneys' fees, court costs, and other related costs and
39+
expenses, arising out of your use of this document irrespective of the cause
40+
of said liability.
41+
MITRE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO WARRANTY,
42+
EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY MERCHANTABILITY,
43+
OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL MITRE BE LIABLE FOR ANY
44+
GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
45+
EVEN IF MITRE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46+
47+
48+
Amendment 1
49+
Copyright © 2004, 2005, 2006, AXE Consultants. All Rights Reserved.
50+
This document may be copied, in whole or in part, in any form or by any means,
51+
as is, or with alterations, provided that (1) alterations are clearly marked as
52+
alterations and (2) this copyright notice is included unmodified in any copy.
53+
Any other use or distribution of this document is prohibited without the prior
54+
express permission of AXE.
55+
You use this document on the condition that you indemnify and hold harmless
56+
AXE, its board, officers, agents, and employees, from any and all liability or
57+
damages to yourself or your hardware or software, or third parties, including
58+
attorneys' fees, court costs, and other related costs and expenses, arising out
59+
of your use of this document irrespective of the cause of said liability.
60+
AXE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO WARRANTY,
61+
EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY MERCHANTABILITY,
62+
OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL AXE BE LIABLE FOR ANY
63+
GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
64+
EVEN IF AXE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
65+
66+
67+
Consolidated Standard
68+
Copyright © 2004, 2005, 2006, Ada-Europe.
69+
This document may be copied, in whole or in part, in any form or by any means,
70+
as is, or with alterations, provided that (1) alterations are clearly marked as
71+
alterations and (2) this copyright notice is included unmodified in any copy.
72+
Any other use or distribution of this document is prohibited without the prior
73+
express permission of Ada-Europe.
74+
You use this document on the condition that you indemnify and hold harmless
75+
Ada-Europe and its Board from any and all liability or damages to yourself or
76+
your hardware or software, or third parties, including attorneys' fees, court
77+
costs, and other related costs and expenses, arising out of your use of this
78+
document irrespective of the cause of said liability.
79+
ADA-EUROPE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO
80+
WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY
81+
MERCHANTABILITY, OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL ADA-EUROPE
82+
BE LIABLE FOR ANY GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR
83+
SPECIAL DAMAGES, EVEN IF ADA-EUROPE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
84+
DAMAGES.

Diff for: build.xml

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
254254
-->
255255

256256
<property name="gen.analysis.dir" value="/org/opensolaris/opengrok/analysis"/>
257+
<run-jflex dir="${gen.analysis.dir}/ada" name="AdaSymbolTokenizer" />
258+
<run-jflex dir="${gen.analysis.dir}/ada" name="AdaXref"/>
257259
<run-jflex dir="${gen.analysis.dir}/c" name="CSymbolTokenizer" />
258260
<run-jflex dir="${gen.analysis.dir}/c" name="CXref"/>
259261
<run-jflex dir="${gen.analysis.dir}/c" name="CxxSymbolTokenizer"/>

Diff for: opengrok-indexer/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
4242
<testSourceDirectory>../test</testSourceDirectory>
4343

4444
<resources>
45+
<resource>
46+
<targetPath>org/opensolaris/opengrok/analysis/ada/</targetPath>
47+
<directory>../src/org/opensolaris/opengrok/analysis/ada/</directory>
48+
<includes>
49+
<include>*.adb</include>
50+
</includes>
51+
</resource>
4552
<resource>
4653
<targetPath>org/opensolaris/opengrok/analysis/sql/</targetPath>
4754
<directory>../src/org/opensolaris/opengrok/analysis/sql/</directory>

Diff for: src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.lucene.document.TextField;
5555
import org.apache.lucene.util.BytesRef;
5656
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
57+
import org.opensolaris.opengrok.analysis.ada.AdaAnalyzerFactory;
5758
import org.opensolaris.opengrok.analysis.archive.BZip2AnalyzerFactory;
5859
import org.opensolaris.opengrok.analysis.archive.GZIPAnalyzerFactory;
5960
import org.opensolaris.opengrok.analysis.archive.TarAnalyzerFactory;
@@ -242,7 +243,8 @@ public class AnalyzerGuru {
242243
new HaskellAnalyzerFactory(),
243244
new GolangAnalyzerFactory(),
244245
new LuaAnalyzerFactory(),
245-
new PascalAnalyzerFactory()
246+
new PascalAnalyzerFactory(),
247+
new AdaAnalyzerFactory()
246248
};
247249

248250
for (FileAnalyzerFactory analyzer : analyzers) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
package org.opensolaris.opengrok.analysis.ada;
25+
26+
import java.io.Reader;
27+
import org.opensolaris.opengrok.analysis.FileAnalyzer;
28+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
29+
import org.opensolaris.opengrok.analysis.JFlexXref;
30+
import org.opensolaris.opengrok.analysis.plain.AbstractSourceCodeAnalyzer;
31+
32+
/**
33+
* Represents an implementation of {@link AbstractSourceCodeAnalyzer} for the
34+
* Ada programming language.
35+
* <p>
36+
* http://www.adaic.org/
37+
*/
38+
public class AdaAnalyzer extends AbstractSourceCodeAnalyzer {
39+
40+
/**
41+
* Creates a new instance of {@link AdaAnalyzer}
42+
* @param factory
43+
*/
44+
protected AdaAnalyzer(FileAnalyzerFactory factory) {
45+
super(factory);
46+
SymbolTokenizer = new AdaSymbolTokenizer(FileAnalyzer.dummyReader);
47+
}
48+
49+
@Override
50+
protected JFlexXref newXref(Reader reader) {
51+
return new AdaXref(reader);
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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) 2010, 2015 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opensolaris.opengrok.analysis.ada;
26+
27+
import org.opensolaris.opengrok.analysis.FileAnalyzer;
28+
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
29+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
30+
31+
/**
32+
* Represents an implementation of {@link FileAnalyzerFactory} to produce
33+
* {@link AdaAnalyzer} instances.
34+
*/
35+
public class AdaAnalyzerFactory extends FileAnalyzerFactory {
36+
37+
private static final String name = "Ada";
38+
39+
private static final String[] SUFFIXES = {
40+
"ADA",
41+
"ADB",
42+
"ADS"
43+
};
44+
45+
public AdaAnalyzerFactory() {
46+
super(null, null, SUFFIXES, null, null, "text/plain", Genre.PLAIN, name);
47+
}
48+
49+
@Override
50+
protected FileAnalyzer newAnalyzer() {
51+
return new AdaAnalyzer(this);
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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, Chris Fraire <[email protected]>.
22+
*/
23+
package org.opensolaris.opengrok.analysis.ada;
24+
25+
import java.io.IOException;
26+
27+
/**
28+
* Represents an API for object's using {@link AdaLexHelper}
29+
*/
30+
interface AdaLexListener {
31+
void pushState(int state);
32+
void popState() throws IOException;
33+
void switchState(int state);
34+
void take(String value) throws IOException;
35+
void takeNonword(String value) throws IOException;
36+
37+
/**
38+
* Passes a text fragment that is syntactically a symbol for processing.
39+
* @param value the excised symbol
40+
* @param captureOffset the offset from yychar where {@code value} began
41+
* @param ignoreKwd a value indicating whether keywords should be ignored
42+
* @return true if the {@code value} was not in keywords or if the
43+
* {@code ignoreKwd} was true
44+
*/
45+
boolean takeSymbol(String value, int captureOffset, boolean ignoreKwd)
46+
throws IOException;
47+
48+
/**
49+
* Indicates that something unusual happened where normally a symbol would
50+
* have been written.
51+
*/
52+
void skipSymbol();
53+
54+
/**
55+
* Passes a text fragment that is syntactically a keyword symbol for
56+
* processing
57+
* @param value the excised symbol
58+
*/
59+
void takeKeyword(String value) throws IOException;
60+
61+
void doStartNewLine() throws IOException;
62+
63+
/**
64+
* Pushes back to the scanner a specified number of characters
65+
* @param numChars
66+
*/
67+
void pushback(int numChars);
68+
}
69+
70+
/**
71+
* Represents a helper for Ada lexers
72+
*/
73+
class AdaLexHelper {
74+
75+
private final AdaLexListener listener;
76+
77+
public AdaLexHelper(AdaLexListener listener) {
78+
if (listener == null) {
79+
throw new IllegalArgumentException("`listener' is null");
80+
}
81+
this.listener = listener;
82+
}
83+
84+
/**
85+
* Write {@code value} to output -- if it contains any EOLs then the
86+
* {@code startNewLine()} is called in lieu of outputting EOL.
87+
*/
88+
public void takeLiteral(String value, String linePrefix, String lineSuffix)
89+
throws IOException {
90+
91+
if (linePrefix != null) listener.take(linePrefix);
92+
93+
int off = 0;
94+
do {
95+
int w = 1, ri, ni, i;
96+
ri = value.indexOf("\r", off);
97+
ni = value.indexOf("\n", off);
98+
if (ri == -1 && ni == -1) {
99+
String sub = value.substring(off);
100+
listener.takeNonword(sub);
101+
break;
102+
}
103+
if (ri != -1 && ni != -1) {
104+
if (ri < ni) {
105+
i = ri;
106+
if (value.charAt(ri) == '\r' && value.charAt(ni) == '\n') {
107+
w = 2;
108+
}
109+
} else {
110+
i = ni;
111+
}
112+
} else if (ri != -1) {
113+
i = ri;
114+
} else {
115+
i = ni;
116+
}
117+
118+
String sub = value.substring(off, i);
119+
listener.takeNonword(sub);
120+
if (lineSuffix != null) listener.take(lineSuffix);
121+
listener.doStartNewLine();
122+
if (linePrefix != null) listener.take(linePrefix);
123+
off = i + w;
124+
} while (off < value.length());
125+
126+
if (lineSuffix != null) listener.take(lineSuffix);
127+
}
128+
}

0 commit comments

Comments
 (0)